import Vue from 'vue';
import Router from 'vue-router';
import Netcall from '@/views/Netcall/Netcall';
import { checkSupport } from '@/utils/Support';
import { errorMessage } from '@/utils/message';

const ErrorPage = () => import('@/views/Error');

Vue.use(Router);

const router = new Router({
  mode: 'hash',
  routes: [
    {
      path: '/index',
      name: 'Netcall',
      component: Netcall
    },
    {
      path: '/error',
      name: 'error',
      component: ErrorPage
    }
  ]
});

router.beforeEach((to, from, next) => {
  if (to.path === '/error') {
    next();
  } else {
    checkSupport().then(() => {
      next();
    }, (error) => {
      errorMessage(error);
      sessionStorage.setItem('msg', error.message);
      next('/error');
      // next();
    });
  }
});

export default router;
